<%@ page import="databeans.*" %>
<%@ page import="java.util.*" %>

<jsp:include page="../common/header.jsp" />

<title>Carnegie Financial Services - Buy Funds</title>
<script type="text/javascript">
	$(document).ready(function() { 
		$('.fund_graph').visualize({type: 'line', parseDirection:'x', pieLabelPos:'outside', height: 230, width:320, colors:['#8CCE3B','#92d5ea','#ee8310','#be1e2d']});
		$('#colorize_1').colorize({ hoverColor:'none', ignoreHeaders :true, hiliteColor :'none' });
		$('#colorize_2').colorize({ hoverColor:'none', ignoreHeaders :true, hiliteColor :'none' });
		
	});
</script>
</head>

<body>
	<div id="container">
    	<div id="header">
        	<h2>Carnegie Financial Services</h2>
    		<jsp:include page="../common/top-menu.jsp" />
      	</div>
        <div id="wrapper">
        	<div id="content">
        	<div id="box">
				<h3>Fund Summary</h3> 
				<%
					Position [] positionList = new Position[0];
					ArrayList<String> fundNames = new ArrayList<String>();;
					if (request.getAttribute("positionList") != null){
					    //activeItems = (ItemType[])request.getAttribute("activeItems");
					    positionList = (Position[])request.getAttribute("positionList");
					    fundNames = (ArrayList<String>)request.getAttribute("fundNames_p");
					    List<Long> remainingPositions = (ArrayList<Long>)request.getAttribute("remainingPositionList");
				%>
				<table id="colorize_1">
					<thead>
						<tr>
							<th>ID</th>
                           	<th>Fund Name</th>
                            <th>Number of Shares</th>
                            <th>Pending Sales</th>
                           </tr>
					</thead>
					<tbody>
					<%
						
						Customer tempCustomer = null;
						
						for (int i = 0; i < positionList.length; i++) {
						    Position tempPosition = positionList[i];
						
					%>
						<tr>
							<td><%=positionList[i].getFundID() %></td>
							<td><%=fundNames.get(i) %></td>
                           	<td><%=Formatter.prepShareToView(positionList[i].getShares())%></td>
                           	<td><%=Formatter.prepShareToView(remainingPositions.get(i)) %></td>
                        </tr>
                        <%
						}
					%>
					</tbody>
				</table>
			</div>
			<div class="padding"></div>
              <div id="box">
	            	<h3>Sell Funds</h3>
	            	<jsp:include page="../common/messages.jsp"/>
	                <form id="form" action="customerSellFund.do" method="post" class="user-form">
	                    <label for="txtFundID" class="label-long">Choose Fund : </label>
	                    <select name="txtFundID" tabindex="1">
						<%
						if(request.getAttribute("fundNames")!= null) {
						    //Fund [] tempFunds = (Fund[])request.getAttribute("fundNames");
						    //Get Map in Set interface to get key and value
					        Map<Object,String> mp = (HashMap)request.getAttribute("fundNames");
						    
						    Set s=mp.entrySet();
					
					        //Move next key and value of Map by iterator
					        Iterator it=s.iterator();
					
					        while(it.hasNext())
					        {
					            // key=value separator this by Map.Entry to get key and value
					            Map.Entry m =(Map.Entry)it.next();
					
					            // getKey is used to get key of Map
					            int key=(Integer)m.getKey();
					
					            // getValue is used to get value of key in Map
					            String value=(String)m.getValue();
					
					            System.out.println("Key :"+key+"  Value :"+value);
					        

						    
						%>
						  		  	<OPTION VALUE="<%=key %>"><%=value %></OPTION>
						<%
					        }
						} else {    
						%>
						    		<OPTION VALUE="">Funds could not be retrieved</OPTION>
						<%
						}
						%>
						</SELECT>
						<br />
	                    <input type="hidden" name="txtSubmissionDate" size="20" value="${txtSubmissionDate}" readonly />
	                    <br />
	                    <label for="txtShares" class="label-long">Number of Shares to sell: </label>
	                    <input type="text" name="txtShares" size="20" value="${txtShares}" tabindex="2"/>
	                    <br />
	                  <div align="center">
	                  <input id="buy-funds" type="submit" name="Submit" value="Submit Sell Request" tabindex="3" /> 
	                  <input id="cancel" type="reset" tabindex="4" value="Cancel" />
	                  </div>
	                </form>
	                <div class="create-emp-result"></div>
                </div>
				<%}else {%>
					<p>You currently do not own any funds!</p>
				<%} %>
            </div>

            <jsp:include page="../common/sidebar.jsp" />
      </div>
        <jsp:include page="../common/footer.jsp" />
</div>
<div id="popup" ></div>
</body>

<%@page import="helper.Formatter"%></html>
